import Mock from "mockjs";

export default [
  {
    url: "/system/getContent",
    method: "get",
    response: ({ query }) => {
      const { name, age } = query;
      return {
        code: 200,
        message: "成功",
        data: {
          name,
          age,
          arrList: Mock.mock({
            "data|10": [
              {
                "id|+1": 1,
                name: "小明",
                age: 20,
              },
            ],
          }).data,
        },
      };
    },
  },

  // 路由配置接口
  {
    url: "/user/getRouteList",
    method: "post",
    response: () => {
      return {
        code: 200,
        message: "成功",
        data: [
          {
            path: "/addRouteTest",
            title: "后端返回路由测试",
            element: "AddRouteTest",
          },
        ],
      };
    },
  },
  {
    url: "/system/postContent",
    method: "post",
    response: ({ body }) => {
      const { status } = body;
      return {
        code: 200,
        message: "成功",
        data: status,
      };
    },
  },
  // 用户登录
  {
    url: "/user/login",
    method: "post",
    response: ({ headers }) => {
      if (headers.authorization === "new_duan_token") {
        return {
          code: 200,
          message: "成功",
          data: "用户登录成功",
        };
      }
      return {
        code: 401,
        message: "失败",
        data: "账号或密码错误",
      };
    },
  },

  // 用户登出（修改为更合理的POST方法）
  {
    url: "/user/logout",
    method: "post",
    response: ({ body }) => {
      const { userName } = body;
      return {
        code: 200,
        message: "成功",
        data: `${userName} 已退出登录`,
      };
    },
  },

  // 保留原GET登出（兼容旧版本）
  {
    url: "/user/loginOut",
    method: "get",
    response: ({ query }) => {
      const { userName } = query;
      return {
        code: 200,
        message: "成功",
        data: `${userName} 已退出登录（GET）`,
      };
    },
  },
  {
    url: "/user/getRefreshToken",
    method: "get",
    response: () => {
      return {
        code: 200,
        message: "token刷新成功",
        data: {
          authorization: "new_duan_token",
          refreshToken: "new_chang_token",
        },
      };
    },
  },
];
